//
//  RegisterViewController.m
//  JZMCFM
//
//  Created by Mc on 15/11/9.
//  Copyright (c) 2015年 陈卓. All rights reserved.
//

#import "RegisterViewController.h"
#import <BmobSDK/Bmob.h>
#import "MyViewController.h"
@interface RegisterViewController ()
@property (strong, nonatomic) IBOutlet UITextField *registerUser;
@property (strong, nonatomic) IBOutlet UITextField *registerPass;
@property (strong, nonatomic) IBOutlet UITextField *secondPass;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)registerButton:(id)sender {
    NSString *message = nil;
    if ([self.registerPass.text isEqualToString:self.secondPass.text]) {
        if ([self.registerUser.text isEqualToString:@""] && [self.registerPass.text isEqualToString:@""]) {
            message = @"用户名或者密码不能为空";
        }else{
            BmobObject *login = [BmobObject objectWithClassName:@"_User"];
            [login setObject:self.registerUser.text forKey:@"username"];
            [login setObject:self.registerPass.text forKey:@"password"];
            [login saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
                if (isSuccessful) {
                    NSLog(@"保存成功");
                    [[LoginMangager sharedInstance] loginSuccessHandle];
                    MyViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"aa"];
                    [self.navigationController pushViewController:vc animated:YES];
                }else{
                    NSLog(@"保存失败");
                }
            }];
            return;
        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
    }else{
        message = @"密码不一致";
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
    }
}
- (IBAction)cancleButton:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
